package cz.hanis.android.pubaccounting.db.tables;

import cz.hanis.android.pubaccounting.db.tables.PubTable.PubColumns;

import android.database.sqlite.SQLiteDatabase;
import android.provider.BaseColumns;

public class ItemTable {

	public static final String TABLE_NAME = "item";

	public static class ItemColumns implements BaseColumns {
		public static final String NAME = "name";
		public static final String ABBREVIATION = "abbreviation";
		public static final String COST = "cost";
		public static final String PUB_ID = "pub_id";
	}

	public static void onCreate(SQLiteDatabase db) {
		StringBuilder sb = new StringBuilder();

		sb.append("CREATE TABLE " + ItemTable.TABLE_NAME + " (");
		sb.append(ItemColumns._ID + " INTEGER PRIMARY KEY, ");
		sb.append(ItemColumns.NAME + " TEXT NOT NULL, ");
		sb.append(ItemColumns.ABBREVIATION + " TEXT, ");
		sb.append(ItemColumns.COST + " REAL, ");
		sb.append(ItemColumns.PUB_ID + " INTEGER NOT NULL, ");
		sb.append("FOREIGN KEY(" + ItemColumns.PUB_ID + ") REFERENCES "
				+ PubTable.TABLE_NAME + "(" + PubColumns._ID + ")");
		sb.append(");");
		db.execSQL(sb.toString());
	}

	public static void onUpgrade(SQLiteDatabase db, int oldVersion,
			int newVersion) {
		db.execSQL("DROP TABLE IF EXISTS " + ItemTable.TABLE_NAME);
		ItemTable.onCreate(db);
	}

}
